
//
//  JJBaseController.swift
//  微博1
//
//  Created by 卷卷 on 15/9/1.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit

//功能模块控制器的基类控制器
//Swift 中，遵守协议，直接，接着写
class JJBaseController: UITableViewController {

        
        //用户登录标记
        var userLogon = false
    //用户登录视图 － 每个控制器各自拥有的 visitorView
    //提示：如果使用懒加载，会在用户登录成功之后，视图仍然被创建，虽然不会影响程序执行，但是会消耗内存
    var visitorView: JJVisitorLoginView?
    
    //var visitorView: JJVisitorLoginView? = JJVisitorLoginView()
    
    //如果 view 不存在，系统会再次调用loadView
     override  func loadView(){
            
            userLogon ? super.loadView() : setupVisitorView()
        }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    }
    
        //设置访问视图
        private func setupVisitorView(){
            
            visitorView = JJVisitorLoginView()
            // 替换跟视图
            view = visitorView
            
            //添加导航栏按钮
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action:"visitorLoginViewWillRegister" )
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")

            //设置按钮监听方法
            visitorView?.registerButton.addTarget(self, action: "visitorLoginViewWillRegister", forControlEvents: UIControlEvents.TouchUpInside)
            visitorView?.loginButton.addTarget(self, action: "visitorLoginViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)
            
            // MARK:VisitorLoginViewDelegate
            
            func visitorLoginViewWillLogin(){
                
                let nav = UINavigationController(rootViewController: JJOAuthViewController())
                
                presentViewController(nav, animated: true, completion: nil)
            }
            
            func visitorLoginViewWillRegister(){
                
                print("注册")
            }
            
        }
    
    
   

    
    }
